package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.EssayCourseCatalog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

public interface EssayCourseCatalogRepository extends JpaRepository<EssayCourseCatalog, Integer> {

    //通过课程id查询所有章节
    @Modifying
    @Transactional
    @Query(value = "select ecc from EssayCourseCatalog ecc where ecc.course.id = ?1")
    List<EssayCourseCatalog> findAllByCourseId(Integer courseId);

    //根据章节id查询章节
    @Query(value = "select ecc from EssayCourseCatalog ecc where ecc.id = ?1")
    EssayCourseCatalog findCatalogById(Integer id);

    //添加章节与写作锦囊绑定
    @Query(value = "update EssayCourseCatalog ecc set ecc.writingMethodBase.id = ?1 where ecc.id = ?2")
    @Transactional
    @Modifying
    void updateCatalogById(Integer methodBaseId, Integer catalogId);
}